/*
 * init_option.c
 *
 *  Created on: 2012/09/04
 *      Author: shenming
 */

#include <stdio.h>
#include "sqlite3.h"
#include "typedef.h"
#include "db_def.h"
#include "core.h"
#include "Id.h"

/*TBL_OPTIONINFO*/
static INT createOptionInfo(sqlite3 *db) {

	INT rc = 0;
	PSZ zErrMsg = NULL;
	PSZ sql_create = NULL;

	sql_create = sqlite3_mprintf("CREATE TABLE %q (TblIndex INTEGER,"
			"%q INTEGER, %q INTEGER, %q TEXT,PRIMARY KEY(TblIndex));",
			TBL_OPTIONINFO, _T_IDX(2), _T_IDX(3 ), _T_IDX(4 ));
	rc = sqlite3_exec(db, sql_create, 0, 0, &zErrMsg);
	if (rc != SQLITE_OK) {
		return rc;
	} else {
		if (sql_create != NULL ) {
			sqlite3_free(sql_create);
		}
	}
	return rc;
}

INT DLL_EXPORT initOption(sqlite3 * db) {
	INT rc = 0;

	rc = createOptionInfo(db);
	if (rc != COEXIT_SUCCESS) {
		return rc;
	}

	return COEXIT_SUCCESS;
}
